Emit 觀念與使用


Posted by hoyi-23 on 2021-08-09

不太清楚 Props 可以參考這篇 Props 觀念與使用


Props 是從父層傳遞到內層內件的方式
而 emit 就是由內層往外層的方式啦!

假設今天有一個元件,元件內包含一個觸發的按鈕,按下去後需要觸發外層的其他東西,就需要使用emit將觸發傳出去!!


CodePen 練習

內層元件有個incrementCounter的觸發事件!
我們先在內層寫入incrementCounter的methods,
incrementCounter的這個內層觸發事件,觸發後要影響外層,就需要在內層的methods內寫,

<div id="app">
  <h2>透過 emit 向外傳遞資訊</h2>
  我透過元件儲值了 {{ cash }} 元
  <button-counter @increment="incrementTotal"></button-counter>
  <hr>
  <button-counter></button-counter>
</div>











Related Posts

Oracle中文數字排序

Oracle中文數字排序

[重新理解 C++]  TMP(1): compiling time recursion

[重新理解 C++] TMP(1): compiling time recursion

[ JavaScript 09 ] String 類型的內建函式

[ JavaScript 09 ] String 類型的內建函式


Comments